<template>
	<view class="goods-detail">
		<!-- 轮播图 -->
		<swiper class="swiper"
						indicator-dots
						circular
						autoplay
						interval="2000">
			<block v-for="(item,index) in imgs" :key="index">
				<swiper-item><image :src="item.src" class="img"></image></swiper-item>
			</block>
		</swiper>
		<!-- 价格显示 -->
		<view class="box1">
			<view class="price">
				<text>¥{{goodDetail.sell_price}}</text>
				<text>¥{{goodDetail.market_price}}</text>
			</view>
			<view class="good-name">{{goodDetail.title}}</view>
		</view>
		<view class="box2">
			<view>货号: {{goodDetail.goods_no}}</view>
			<view>库存: {{goodDetail.stock_quantity}}</view>
		</view>
		<view class="box3">
			<view class="tit">
				商品介绍
			</view>
			<view class="content">
				<rich-text :nodes="info.content"></rich-text>
			</view>
		</view>
		<view class="nav">
			<uni-goods-nav :fill="true"  :options="options" :buttonGroup="buttonGroup"  @click="onClick" @buttonClick="buttonClick" />
		</view>
	</view>  
</template>

<script>
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue'
	export default {
		data() {
			return {
				id: 0,
				imgs: [],
				goodDetail: {},
				info: {},
				options: [
					{
				    icon: 'headphones',
				    text: '客服'
				  }, {
				    icon: 'shop',
				    text: '店铺',
				    info: 0,
				    infoBackgroundColor:'#007aff',
				    infoColor:"red"
				  }, {
				    icon: 'cart',
				    text: '购物车',
				    info: 0
				   }],
				buttonGroup: [
					{
				    text: '加入购物车',
				    backgroundColor: '#ff0000',
				    color: '#fff'
				  },
				  {
				    text: '立即购买',
				    backgroundColor: '#ffa200',
				    color: '#fff'
				  }
				]
			}
		},
		components: {
			uniGoodsNav
		},
		methods: {
			onClick (e) {
			  uni.showToast({
			  title: `点击${e.content.text}`,
			  icon: 'none'
				})
			},
			buttonClick (e) {
			  console.log(e)
			  this.options[2].info++
			},
			async getSwiper() {
				const res = await this.$http({
					url: '/getthumimages/' + this.id
				})
				if(res.statusCode !== 200) return uni.showToast({
					title: '获取轮播图数据错误'
				})
				this.imgs = res.data.message
			},
			async getDetailInfo() {
				const res = await this.$http({
					url: '/goods/getinfo/'+this.id
				})
				if(res.statusCode !== 200) return uni.showToast({
					title: '获取数据错误'
				})
				this.goodDetail = res.data.message[0]
			},
			async getDetailContent() {
				const res = await this.$http({
					url: '/goods/getdesc/'+this.id
				})
				if(res.statusCode !== 200) return uni.showToast({
					title: '获取详情数据错误'
				})
				this.info = res.data.message[0]
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getSwiper()
			this.getDetailInfo()
			this.getDetailContent()
		}
	}
</script>

<style lang="scss">
	.swiper {
		height: calc(100vw * 240 / 320 );
	}
	.img {
		width: 100%;
	}
	.box1 {
		margin-top: 10rpx;
		padding: 0 20rpx;
		line-height: 50rpx;
		margin-bottom: 10rpx;
		.price {
			color: red;
			text:nth-child(2) {
				font-size: 28rpx;
				text-decoration: line-through;
				color: #888888;
				padding-left: 20rpx;
			}
		}
	}
	.box1, .box2, .box3 {
		font-size: 36rpx;
	}
	.box2 {
		padding: 0 20rpx;
		line-height: 70rpx;
		border-top: 8rpx solid #eee;
		border-bottom: 8rpx solid #eee;
	}
	.box3 {
		padding: 6rpx 20rpx;
		margin-top: 50rpx;
		.tit {
			border-bottom: 1px solid #eee;
			line-height: 60rpx;
		}
		.content {
			padding: 10rpx;
			font-size: 28rpx;
			overflow: hidden;
		}
	}
	.nav {
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
	}
</style>
